package br.com.ledger.utils;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

import br.com.ledger.model.TipoUsuarioBean;


public class Utils {

	
	public static boolean isProfessor() {
		return (Main.Ledger.getUsuario().getTipo_usuario() == TipoUsuarioBean.PROFESSOR);
	}
	
	public static ImageIcon getImage(Object o, String name) {
		return new ImageIcon(o.getClass().getResource("/res/" + name));
	}
	
	public static Point getPosicaoCentral(Dimension tamanho) {
		int xl = Toolkit.getDefaultToolkit().getScreenSize().width/2 - tamanho.width/2;
		int yl = Toolkit.getDefaultToolkit().getScreenSize().height/2 - tamanho.height/2;
		return new Point(xl,yl);
	}
	
	public static File getPDFile() {
		JFileChooser jfc = new JFileChooser();
		jfc.addChoosableFileFilter(new FileNameExtensionFilter("Documento Portable Document Format (PDF)", "PDF"));
		jfc.setAcceptAllFileFilterUsed(false);
		jfc.setDialogTitle("Salvar");
		if (jfc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
			if (jfc.getSelectedFile().getAbsolutePath().endsWith(".pdf"))
				return jfc.getSelectedFile();
			else
				return new File(jfc.getSelectedFile().getAbsolutePath() + ".pdf");
		} else {
			return null;
		}
	}
}
